<?php

namespace app\common\model;

use think\Model;

/**
 * 微信错误收集
 */
class Logs Extends Model
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = false;
    // 追加属性
    protected $append = [
    ];
    public static function addLog($title,$desc,$wechat_id,$action=""){
    	$wxname = db('wechats')->where('id',intval($wechat_id))->value("wxname");
    	if(!empty($wxname)){
    		$wxname = "【".$wxname."】公众号";
    	}
    	$title = str_replace("%s", $wxname, $title);
    	return self::insert([
    		'wechat_id' => $wechat_id,
    		'title' => $title,
    		'desc' =>(is_array($desc) ? json_encode($desc,JSON_UNESCAPED_UNICODE) : $desc),
    		'action' => $action,
    		'created_at' => time()
    	]);
    }	
}
